﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace D20.Entities.Items
{
    /// <summary>
    /// A non-character entity.
    /// </summary>
    public class Item : Entity
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="Item"/> class.
        /// </summary>
        public Item()
        {
        }

        /// <summary>
        /// Gets or sets a value indicating whether this <see cref="Item"/> is broken.
        /// </summary>
        /// <value><c>true</c> if broken; otherwise, <c>false</c>.</value>
        public bool Broken
        {
            get { return Health <= 0; }
            set
            {
                if (value == true)
                {
                    Debug.Assert(PreviousHealth > 0, "PreviousHealth > 0");
                    if (PreviousHealth <= 0)
                    {
                        throw new InvalidOperationException("Item is already broken.");
                    }
                    Health = 0;
                }
                else
                {
                    Debug.Assert(Health <= 0);
                    if (Health > 0)
                    {
                        throw new InvalidOperationException("Item isn't broken.");
                    }
                    Debug.Assert(PreviousHealth > 0, "PreviousHealth > 0");
                    if (PreviousHealth <= 0)
                    {
                        throw new InvalidOperationException("PreviousHealth isn't positive.");
                    }
                    Revive(null, PreviousHealth);
                }

            }
        }
        private int weight, volume;


        /// <summary>
        /// Gets or sets the weight.
        /// </summary>
        /// <value>The weight.</value>
        public int Weight
        {
            get { return weight; }
            set
            {
                Debug.Assert(value >= 0, "value >= 0");
                if (value < 0)
                {
                    throw new ArgumentOutOfRangeException("value", "Weight must be positive.");
                }
                weight = value;
            }
        }
        /// <summary>
        /// Gets or sets the volume.
        /// </summary>
        /// <value>The volume.</value>
        public int Volume
        {
            get { return volume; }
            set
            {
                Debug.Assert(value >= 0, "value >= 0");
                if (value < 0)
                {
                    throw new ArgumentOutOfRangeException("value", "Volume must be positive");
                }
                volume = value;
            }
        }
    }
}
